package com.iwomy.secureplat.platform.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.secureplat.common.core.util.R;
import com.iwomy.secureplat.common.log.annotation.SysLog;
import com.iwomy.secureplat.platform.entity.AlarmFaultHandleLoggingEntity;
import com.iwomy.secureplat.platform.entity.AlarmFaultLoggingEntity;
import com.iwomy.secureplat.platform.service.AlarmFaultHandleLoggingService;
import com.iwomy.secureplat.platform.service.AlarmFaultLoggingService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.iwomy.secureplat.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * ${tableComment}
 *
 * @author pig
 * @date 2023-12-26 19:20:40
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/alarmFaultHandleLogging" )
@Tag(description = "alarmFaultHandleLogging" , name = "${tableComment}管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AlarmFaultHandleLoggingController {

    private final  AlarmFaultHandleLoggingService alarmFaultHandleLoggingService;

    private final AlarmFaultLoggingService alarmFaultLoggingService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param alarmFaultHandleLogging ${tableComment}
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('platform_alarmFaultHandleLogging_view')" )
    public R getAlarmFaultHandleLoggingPage(@ParameterObject Page page, @ParameterObject AlarmFaultHandleLoggingEntity alarmFaultHandleLogging) {
        LambdaQueryWrapper<AlarmFaultHandleLoggingEntity> wrapper = Wrappers.lambdaQuery(alarmFaultHandleLogging);
        return R.ok(alarmFaultHandleLoggingService.page(page, wrapper));
    }


    /**
     * 通过id查询${tableComment}
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('platform_alarmFaultHandleLogging_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(alarmFaultHandleLoggingService.getById(id));
    }

    /**
     * 新增${tableComment}
     * @param alarmFaultHandleLogging ${tableComment}
     * @return R
     */
    @Operation(summary = "新增${tableComment}" , description = "新增${tableComment}" )
    @SysLog("新增${tableComment}" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('platform_alarmFaultHandleLogging_add')" )
    public R save(@RequestBody AlarmFaultHandleLoggingEntity alarmFaultHandleLogging) {

		AlarmFaultLoggingEntity alarmFaultLoggingEntity = new AlarmFaultLoggingEntity();
		alarmFaultLoggingEntity.setId(alarmFaultHandleLogging.getAlarmFaultLoggingId());
		alarmFaultLoggingEntity.setRemarks(alarmFaultHandleLogging.getRemarks());
		alarmFaultLoggingService.updateById(alarmFaultLoggingEntity);

        return R.ok(alarmFaultHandleLoggingService.save(alarmFaultHandleLogging));
    }

    /**
     * 修改${tableComment}
     * @param alarmFaultHandleLogging ${tableComment}
     * @return R
     */
    @Operation(summary = "修改${tableComment}" , description = "修改${tableComment}" )
    @SysLog("修改${tableComment}" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('platform_alarmFaultHandleLogging_edit')" )
    public R updateById(@RequestBody AlarmFaultHandleLoggingEntity alarmFaultHandleLogging) {
        return R.ok(alarmFaultHandleLoggingService.updateById(alarmFaultHandleLogging));
    }

    /**
     * 通过id删除${tableComment}
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除${tableComment}" , description = "通过id删除${tableComment}" )
    @SysLog("通过id删除${tableComment}" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('platform_alarmFaultHandleLogging_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(alarmFaultHandleLoggingService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param alarmFaultHandleLogging 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('platform_alarmFaultHandleLogging_export')" )
    public List<AlarmFaultHandleLoggingEntity> export(AlarmFaultHandleLoggingEntity alarmFaultHandleLogging,Long[] ids) {
        return alarmFaultHandleLoggingService.list(Wrappers.lambdaQuery(alarmFaultHandleLogging).in(ArrayUtil.isNotEmpty(ids), AlarmFaultHandleLoggingEntity::getId, ids));
    }
}